<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改产品风格')" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-style-edit" th:object="${style}">
        <input id="styleId" name="styleId" type="hidden" th:field="*{styleId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">风格名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="styleName" id="styleName" th:field="*{styleName}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">风格备注：</label>
            <div class="col-sm-8">
                <textarea id="styleDesc" name="styleDesc" class="form-control" th:field="*{styleDesc}">[[*{styleDesc}]]</textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: ztree-js" />
<script type="text/javascript">

    $("#form-style-edit").validate({
        onkeyup: false,
        rules:{
            styleName:{
                remote: {
                    url: ctx + "datum/style/checkStyleNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "styleId": function() {
                            return $("#styleId").val();
                        },
                        "styleName": function() {
                            return $.common.trim($("#styleName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            roleSort:{
                digits:true
            },
        },
        messages: {
            "styleName": {
                remote: "产品风格名称已经存在"
            },
        },
        focusCleanup: true
    });

    function edit() {
        var styleId = $("input[name='styleId']").val();
        var styleName = $("input[name='styleName']").val();
        var styleDesc = $("textarea[name='styleDesc']").val();
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "datum/style/edit",
            data : {
                "styleId": styleId,
                "styleName": styleName,
                "styleDesc": styleDesc,
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.successCallback(data);
            }
        });
    }

    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }
</script>
</body>
</html>
